define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cms/articlemanage/index',
                    add_url: 'cms/articlemanage/add',
                    edit_url: 'cms/articlemanage/edit',
                    del_url: 'cms/articlemanage/del',
                    multi_url: 'cms/articlemanage/multi',
                    table: 'article_manage',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'articlecategory_id', title: __('Articlecategory_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'title', title: __('Title')},
                        {field: 'clickrate', title: __('Clickrate')},
                        {field: 'commentrate', title: __('Commentrate')},
                        {field: 'goodrate', title: __('Goodrate')},
                        {field: 'key_word', title: __('Key_word')},
                        {field: 'source', title: __('Source')},
                        {field: 'smallimage', title: __('Smallimage'), formatter: Table.api.formatter.image},
                        {field: 'publishstatus', title: __('Publishstatus'), visible:false, searchList: {"0":__('Publishstatus 0'),"1":__('Publishstatus 1')}},
                        {field: 'publishstatus_text', title: __('Publishstatus'), operate:false},
                        {field: 'set_topstatus', title: __('Set_topstatus'), visible:false, searchList: {"0":__('Set_topstatus 0'),"1":__('Set_topstatus 1')}},
                        {field: 'set_topstatus_text', title: __('Set_topstatus'), operate:false},
                        {field: 'recommendstatus', title: __('Recommendstatus'), visible:false, searchList: {"0":__('Recommendstatus 0'),"1":__('Recommendstatus 1')}},
                        {field: 'recommendstatus_text', title: __('Recommendstatus'), operate:false},
                        {field: 'commentstatus', title: __('Commentstatus'), visible:false, searchList: {"1":__('Commentstatus 1'),"0":__('Commentstatus 0')}},
                        {field: 'commentstatus_text', title: __('Commentstatus'), operate:false},
                        {field: 'deletestatus', title: __('Deletestatus'), visible:false, searchList: {"0":__('Deletestatus 0'),"1":__('Deletestatus 1')}},
                        {field: 'deletestatus_text', title: __('Deletestatus'), operate:false},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'published_time', title: __('Published_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'delete_time', title: __('Delete_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('normal'),"hidden":__('hidden')}},
                        {field: 'status_text', title: __('Status'), operate:false},
                        {field: 'articlecategory.name', title: __('Articlecategory.name')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});